package com.bluestone.scripts;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.xml.bind.annotation.adapters.XmlAdapter;


/**
 * <pre>
 * 
 * Accela IVR
 * Created Date: Sep 14, 2009
 * 
 * Accela, Inc.
 * Copyright (C): 2009
 * 
 * Description: 
 * 
 * 
 * Notes:
 * $Id: StringMapAdapter.java jliu $
 * </pre>
 */
public class KeyValueMapAdapter extends XmlAdapter<KeyValueEntryList, Map<String, String>>  {

	@Override
	public KeyValueEntryList marshal(Map<String, String> v) throws Exception {
    	//System.out.println("marshalv " + v);
		
		KeyValueEntryList myMap = new KeyValueEntryList();
		if ( v!= null ) {
			List<KeyValueEntry> aList = myMap.getElements();
	        for ( Map.Entry<String, String> e : v.entrySet() ) {
	            aList.add(new KeyValueEntry(e.getKey(), e.getValue()));
	        }
		}
        return myMap;
	}

	@Override
	public Map<String, String> unmarshal(KeyValueEntryList v) throws Exception {
    	//System.out.println("unmarshalv " + v);
		
		Map<String, String> map = new HashMap<String, String>();
		if ( v!= null ) {
	        for ( KeyValueEntry e : v.getElements() ) {
	            map.put(e.getKey(), e.getValue());
	        }
		}
        return map;
	}

}
